package com.gopay.common.user.dao.impl;

import com.gopay.common.base.dao.impl.BaseDAOImpl;
import com.gopay.common.constants.bank.PabConstants;
import com.gopay.common.domain.cust.CustSettledInfo;
import com.gopay.common.user.dao.CustSettledInfoDao;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import java.io.Serializable;
import java.util.List;

/**
 * @author jianglijun
 * @ClassName: 类名称
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @date 2016年6月16日 下午3:57:35
 */
@Repository("custSettledInfoDao")
public class CustSettledInfoDaoImpl extends BaseDAOImpl<CustSettledInfo, Serializable>implements CustSettledInfoDao {
	/**
	 * 通过商户ID查询商户入驻信息
	 * 
	 * @param custId
	 * @return
	 */
	@Override
	public List<CustSettledInfo> getCustSettledInfoByCustId(String custId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
		criteria.add(Restrictions.eq("custId", custId));
		List<CustSettledInfo> list = this.findByCriteria(criteria);
		return list;
	}

	/**
	 * 通过商户ID和入驻类型(微信或者支付宝)查询商户入驻信息
	 * 
	 * @param custId
	 * @param type
	 * @return
	 */
	@Override
	public CustSettledInfo getCustSettledInfoByCustIdAndType(String custId, String type) {
		DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
		criteria.add(Restrictions.eq("custId", custId));
		criteria.add(Restrictions.eq("type", type));
		List<CustSettledInfo> list = this.findByCriteria(criteria);
		return list.size() > 0 ? list.get(0) : null;
	}

	@Override
	public CustSettledInfo getCustSettledInfo(String custId, String type, String stat) {
		DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
		criteria.add(Restrictions.eq("custId", custId));
		criteria.add(Restrictions.eq("type", type));
		criteria.add(Restrictions.eq("stat", stat));
		List<CustSettledInfo> list = this.findByCriteria(criteria);
		return list.size() > 0 ? list.get(0) : null;
	}

	@Override
	public CustSettledInfo getCustSettledInfoByPram(String merchantCode, String type) {
		DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
		criteria.add(Restrictions.eq("merchantCode", merchantCode));
		criteria.add(Restrictions.eq("type", type));
		List<CustSettledInfo> list = this.findByCriteria(criteria);
		return list.size() > 0 ? list.get(0) : null;
	}

	@Override
	public CustSettledInfo getCustSettledInfoByCustIdAndChannel(String custId,String type, String channel) {
		DetachedCriteria criteria = DetachedCriteria.forClass(CustSettledInfo.class);
		criteria.add(Restrictions.eq("custId", custId));
		criteria.add(Restrictions.eq("type", type));
		criteria.add(Restrictions.eq("channel", channel));
		criteria.add(Restrictions.eq("stat", PabConstants.SETTLED_SUCCESS));
		List<CustSettledInfo> list = this.findByCriteria(criteria);
		return list.size() > 0 ? list.get(0) : null;
	}
}
